﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;

namespace RevitReadAutoCAD.DotNetRevit
{
    public static class CadHelper
    {
        public static string GetCadPath(Document doc, Reference reference)
        {
            //Reference reference = uiDoc.Selection.PickObject(ObjectType.Element, "选择链接cad文件");
            Element elem = doc.GetElement(reference);
            CADLinkType type = doc.GetElement(elem.GetTypeId()) as CADLinkType;
            string filePath = ModelPathUtils.ConvertModelPathToUserVisiblePath(type.GetExternalFileReference().GetAbsolutePath());
            return filePath;
        }

        public static string GetCadPath(this Element ele)
        {
            Document doc = ele.Document;
            string filepath = "";

            if (ele is ImportInstance)
            {
                var instance = ele as ImportInstance;
                var cadtype = doc.GetElement(instance.GetTypeId()) as CADLinkType;
                if (cadtype != null)
                {
                    filepath = ModelPathUtils.ConvertModelPathToUserVisiblePath(cadtype.GetExternalFileReference().GetAbsolutePath());
                }
            }
            return filepath;
        }

    }
}
